let username = getKey("is").username;

// 检查登陆状态
function isLogin() {
    if (localStorage.getItem("is") == null || JSON.parse(localStorage.getItem("is")).isLogin !== "true") {
        window.location.href = "../html/login.html";
        alert("当前未登录，即将返回登录页面");
    }
}


// 检查
function check() {
    let password = getDocValue("password");
    if (password === "" || password == null) {
        printError("passwordErr", "请输入密码");
    } else if (getKey(username).password !== password) {
        printError("passwordErr", "密码错误");
    } else {
        printError("passwordErr", "");
        let r = confirm("确定注销账号？这是最后一次确认。\n您真的将失去此账号很久很久！");
        if (r === true) closeAccount(username);
        else return false;
    }
    return false;
}

// 注销
function closeAccount(username) {
    let is = JSON.stringify({"username": username, "isLogin": "false"});
    localStorage.setItem("is", is);
    localStorage.removeItem(username);
    alert("注销成功，再见");
    isLogin();
}

// 显示信息
function printError(elemId, histMsg) {
    document.getElementById(elemId).innerHTML = histMsg;
}

// 从页面获取元素
function getDocValue(elemId) {
    return document.getElementById(elemId).value;
}

// 从浏览器获取数据
function getKey(key) {
    return JSON.parse(localStorage.getItem(key));
}